package com.example.textview.gridview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.textview.R;

public class MyGridViewAdapte extends BaseAdapter {

    private Context context;
    private LayoutInflater layoutInflater;
    public MyGridViewAdapte(Context context){
            this.context=context;
            layoutInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }
    static class ViewHolder{
        public ImageView imageView;
        public TextView textView;

    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if(view==null)
        {
            view=layoutInflater.inflate(R.layout.layout_grid_item,null);
            holder=new ViewHolder();
            holder.imageView=view.findViewById(R.id.iv_grid1);
            holder.textView=view.findViewById(R.id.tv_title1);
            view.setTag(holder);
        }
        else {

            holder=(ViewHolder) view.getTag();
        }


        //赋值
        holder.textView.setText("花tttttt");
        Glide.with(context).load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1593538777001&di=900630a5adbde0aa4e88e2383000053d&imgtype=0&src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fphotoblog%2F1005%2F07%2Fc1%2F3788188_3788188_1273170598203_mthumb.jpg").into(holder.imageView);

        //Glide.with(context).load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1593502249697&di=f51d9232bea665f63783da0ac7601f0a&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2Ff31fbe096b63f624a76a76948644ebf81a4ca376.jpg").into(holder.imageView);
        return view;
    }
}
